package com.tanhua.api.impl.mongo;

import com.tanhua.api.mongo.OptionsApi;
import com.tanhua.domain.mongo.Options;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;
@Service
public class OptionsApiImpl implements OptionsApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Options> getOptionsByTitleId(String titleId) {
        Query query = new Query(Criteria.where("titleId").is(titleId));
        List<Options> optionsList = mongoTemplate.find(query, Options.class);
        return optionsList;
    }

    @Override
    public Integer getScore(String questionId, String optionId) {
        Query query = new Query(Criteria.where("titleId").is(questionId).and("optionId").is(optionId));
        Options op = mongoTemplate.findOne(query, Options.class);
        Integer score = op.getScore();
        return score;
    }
}
